package de.ret_world.openrpgstudio.editor.script;

/**
 * A simple Point class.
 *
 * @author Emu
 */
public class Point implements Comparable<Point> {

    private Float x;
    private Float y;

    public Point(Float x, Float y) {
        this.x = x;
        this.y = y;
    }

    public Point(int x, int y) {
        this.x = (float) x;
        this.y = (float) y;
    }

    public Float getX() {
        return x;
    }

    public Float getY() {
        return y;
    }

    public void setX(Float x) {
        this.x = x;
    }

    public void setY(Float y) {
        this.y = y;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Point other = (Point) obj;
        if (this.x != other.x && (this.x == null || !this.x.equals(other.x))) {
            return false;
        }
        if (this.y != other.y && (this.y == null || !this.y.equals(other.y))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 79 * hash + (this.x != null ? this.x.hashCode() : 0);
        hash = 79 * hash + (this.y != null ? this.y.hashCode() : 0);
        return hash;
    }

    @Override
    public int compareTo(Point o) {
        if (x < o.getX() || y < o.getY()) {
            return -1;
        }
        if (x > o.getX() || y > o.getY()) {
            return 1;
        }
        if (x == o.getX()) {
            if (y < o.getY()) {
                return -1;
            }
            if (y > o.getY()) {
                return 1;
            }
            if (y == o.getY()) {
                return 0;
            }
        }
        return 0;
    }

    @Override
    public String toString() {
        return "[P: " + x + "/" + y + "]";
    }
}
